import random

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (QWidget)

from app.Frame import Frame
from app.Index import Index


class Main(QWidget):
    def __init__(self):
        super().__init__()

    def renderApp(self):
        # 渲染应用框架UI
        Frame().renderFrame(self)
        # 渲染应用首页UI
        print('渲染应用首页UI:renderIndex')
        self.index = Index()
        self.index.renderIndex(self)

    def keyPressEvent(self, e):
        """
        控制事件绑定
        """
        if e.key() == Qt.Key_Escape:
            self.close()

    def testButtonCallback(self):
        print("click testButtonCallback:")
        self.index.postMessageToHtml('testButtonCallback')

    def testButton2Callback(self):
        print("click testButton2Callback:")
        self.index.evalJS("output", "Python send string to Html:" + str(random.randint(0, 9)))
